package com.example.music_project.mapper;

import com.example.music_project.model.MusicInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;

@Mapper
public interface MusicMapper {
    //插入音乐文件
    Integer insertFile( MusicInfo music);
    //通过id查询音乐
    @Select("select * from music_info where id = #{id}")
    MusicInfo queryById(Integer id);
    //删除音乐
    @Delete("delete from music_info where id = #{id}")
    Integer deleteMusic(Integer id);
    //查询所有音乐
    @Select("select * from music_info")
    List<MusicInfo> queryAllMusic();
    //模糊匹配查询音乐
    @Select("select * from music_info where title like concat('%',#{musicName},'%')")
    List<MusicInfo> queryByMusicName(String musicName);
    //查询用户是否已经收藏
    @Select("select * from music_love where user_id = #{userId} and music_id = #{musicId}")
    MusicInfo queryByUserIdAndMusicId(@Param("userId")Integer userId, @Param("musicId")Integer musicId);
    //收藏音乐
    @Insert("insert into music_love(user_id, music_id) value(#{userId}, #{musicId})")
    Integer collectMusic(@Param("userId") Integer userId, @Param("musicId") Integer musicId);

    //查询收藏的音乐
    @Select("select mi.* from music_love ml, music_info mi where ml.music_id = mi.id and ml.user_id = #{userId}")
    List<MusicInfo> queryAllCollect(Integer userId);

    //查询指定的或模糊匹配
    @Select("select mi.* from music_love ml, music_info mi where ml.music_id = mi.id and ml.user_id = #{userId} and title like concat('%',#{musicName},'%')")
    List<MusicInfo> queryPoint(@Param("userId") Integer userId, @Param("musicName") String musicName);

    //取消收藏音乐
    @Delete("delete from music_love where user_id = #{userId} and music_id = #{musicId}")
    Integer deleteCollectMusic(@Param("userId") Integer userId, @Param("musicId") Integer musicId);


}
